$server = 'http://localhost:8080/';

window.onload = function(){
	$.ajax({
		type: "POST",
		url: $server+'shipping/list.do',
		crossDomain:true, //设置跨域为true
		xhrFields:{
			withCredentials: true // 携带跨域cookie
		},
		success: function(result){
			console.log(result);
			if (result.code == 200){
				$('.numberNow')[0].innerHTML = result.data.list.length;
				
				$htmlstr = '';
				
				$.each(result.data.list, function(index, value){
					$htmlstr += '<div class="add_AddMain">' +
						'<ul>' +
							'<li>' +
								'<h5>'+value.receiverName	+'</h5>' +
							'</li>' +
							'<li><a href="#">'+value.receiverCity+'</a></li>' +
							'<li><a style=" color: #fff;">一键购</a></li>' +
						'</ul>' +
						'<ul class="userAddress">' +
							'<li>收货人： <span>'+value.receiverName+'</span></li>' +
							'<li>所在地区： <span>'+value.receiverCity+value.receiverDistrict+'</span></li>' +
							'<li>地址： <span>'+value.receiverAddress+'</span></li>' +
							'<li>手机： <span>'+value.receiverPhone+'</span></li>' +
						'</ul>' +
						'<ul>' +
							'<li>支付方式：在线支付</li>' +
							'<li>配送方式：普通快递配送</li>' +
						'</ul>' +
						'<ul class="address_Reset">' +
							'<li><a href="#">设为默认</a></li>' +
							'<li><a href="#">编辑</a></li>' +
						'</ul>' +
					'</div>';
				});				
				$('#box')[0].innerHTML = $htmlstr;
			}else{
				alert(result.msg);
			}
		}
	});
}

$('.add_AddBtn').click(function () {
	alert('msg');
//         addFrom($('.addAddTotal'),$('.addAddTotal li input'),$('.addAddTotal li label'),addNew.find('.userAddress span'),$('.add_AddMain'));
//         $('.numberNow').text($('.add_AddMain .userAddress').length);
});

function addShipping(){
	$userNmaeInput = $('#userNmaeInput').val();
	$receiverCity = $('#receiverCity').val();
	$receiverDistrict = $('#receiverDistrict').val();
	$receiverAddress = $('#receiverAddress').val();
	$phoneInput = $('#phoneInput').val();
	$receiverZip = $('#receiverZip').val();
	
	if ($userNmaeInput == "" || $receiverCity == "" || $receiverDistrict == "" || $receiverAddress == "" || $phoneInput == "" || $receiverZip == ""){
		alert('字段输入不完整');
		return;
	}
	
	$.ajax({
		type: "POST",
		url: $server+'shipping/add.do',
		data: {receiverName:$userNmaeInput, receiverPhone:$phoneInput, receiverCity:$receiverCity, receiverDistrict:$receiverDistrict,
		receiverAddress:$receiverAddress, receiverZip:$receiverZip},
		crossDomain:true, //设置跨域为true
		xhrFields:{
			withCredentials: true // 携带跨域cookie
		},
		success: function(result){
			console.log(result);
			if (result.code == 200){
				alert(result.msg);
			}else{
				alert(result.msg);
			}
			window.location.reload();
		}
	});
}